import 'package:cat_eye/base/base_refresh_state.dart';
import 'package:cat_eye/bean/sq_lite_bean.dart';
import 'package:cat_eye/config/string_config.dart';
import 'package:cat_eye/root_page/home_page/video/video_play_widget.dart';
import 'package:cat_eye/util/util.dart';
import 'package:cat_eye/view_model/other_myattention_view_model.dart';
import 'package:flutter/material.dart';

/*
* @Package: root_page.my_attention_page
* @ClassName: my_attention_video_widget
* @Author: szj
* @CreateDate: 8/3/21 4:48 PM
* TODO 我的关注视频页面
*/
class MyAttentionVideoWidget extends StatefulWidget {
  //视频必要地址
  final String videoUrl;

  //视频背景
  final String background;

  const MyAttentionVideoWidget(
      {Key key, @required this.videoUrl, @required this.background})
      : super(key: key);

  @override
  _MyAttentionVideoWidgetState createState() => _MyAttentionVideoWidgetState();
}

class _MyAttentionVideoWidgetState extends BaseRefreshState<
    MyAttentionVideoWidget, OtherMyAttentionViewModel> {
  @override
  OtherMyAttentionViewModel get buildViewModel =>
      OtherMyAttentionViewModel(widget.videoUrl);

  @override
  Widget buildWidget(BuildContext context, OtherMyAttentionViewModel model) {
    return Scaffold(
      body: Container(
        height: MediaQuery.of(context).size.height,
        decoration: _decoration(context),
        padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
        child: CustomScrollView(
          slivers: [
            SliverToBoxAdapter(
              child: VideoPlayWidget(
                url: widget.videoUrl,
              ),
            ),
            SliverToBoxAdapter(
              child: Padding(
                padding: EdgeInsets.all(10),
                child: Text(
                  StringConfig.FOLLOW_SUCCESS_CONTENT,
                  style: TextStyle(
                      color: Colors.white,
                      fontWeight: FontWeight.bold,
                      fontSize: 16),
                ),
              ),
            ),
            _otherList(model.sqList)
          ],
        ),
      ),
    );
  }


  Widget _otherList(List<SqLiteBean> sqList) {
    return SliverList(
        delegate: SliverChildBuilderDelegate((context, index) {
      return InkWell(
        onTap: () {
          //先关闭当前页面
          Navigator.pop(context);
          //跳转页面
          Navigator.push(
              context,
              router(
                  widget: MyAttentionVideoWidget(
                videoUrl: sqList[index].videoUrl,
                background: sqList[index].background,
              )));
        },
        child: Row(
          children: [
            //左侧Image
            Padding(
              padding: EdgeInsets.only(left: 10, right: 10, top: 10),
              child: cacheImage(
                sqList[index].bodyImageUrl,
                width: 160,
                height: 100,
                borderRadius: BorderRadius.circular(12),
              ),
            ),

            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    sqList[index].title,
                    style: TextStyle(color: Colors.white, fontSize: 14),
                  ),
                  Padding(
                    padding: EdgeInsets.only(top: 5),
                    child: Text(
                      sqList[index].time,
                      style: TextStyle(color: Colors.white, fontSize: 12),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      );
    }, childCount: sqList.length));
  }

  /*
   *   TODO 设置背景色
   *
   *   MediaQuery.of(context).size.height [屏幕高]
   *   MediaQuery.of(context).size.width  [屏幕宽]
   *   ${图片路径}/thumbnail/屏幕高 x 屏幕宽  [让图片占满全屏]
   */
  Decoration _decoration(BuildContext context) {
    print("Decoration背景色为:${widget.background}");
    return BoxDecoration(
      image: DecorationImage(
          //背景图片
          fit: BoxFit.cover,
          // http://img.kaiyanapp.com/2129708dda66e25ae11490a2402603d5.jpeg?imageMogr2/quality/60/format/jpg}/thumbnail/300x600
          image: cachedNetworkImageProvider(
              "${widget.background}/thumbnail/${MediaQuery.of(context).size.height}x${MediaQuery.of(context).size.width}")),
    );
  }
}
